import os
import os.path

import kuai
from kuai.dff.dffdb import Database

DATABASE_NAME = r'C:\Users\madlee\Desktop\Test.dffdb'
TABLE_NAME = 'AMBER'
FORCE_FILED_TYPE = 'AMBER'
MSD_FOLDER = r'C:\Users\madlee\Documents\Job\Direct Force Field\7\debug\NewProject' 

REQUIRED_TERM = ["ATC", "BINC", "N12_6", "BHARM", "AHARM", "TCOSP", "IBCOS"]


# Create the database
# db = Database.create(DATABASE_NAME, TABLE_NAME, FORCE_FILED_TYPE)

# Checkin/Setup the init data
# ff, eqt = kuai.read_ff(r'C:\Users\madlee\Desktop\AMBER3.ppf')
# db = Database(DATABASE_NAME, TABLE_NAME)
# version, newdata = db.checkin(ff, eqt)
# print version, len(newdata)

# Check out the data for molecules
from sets import Set
required = set()
for file in os.listdir(MSD_FOLDER):
    if file.endswith('.msd'):
        mol = kuai.read_mol(os.path.join(MSD_FOLDER, file))
        keys = kuai.ForceField.list_keys(mol, REQUIRED_TERM)
        required = required.union(set(keys))

db = Database(DATABASE_NAME, TABLE_NAME)
ff, eqt = db.checkout(required)
print ff
print eqt
    


# Export All result
# db = Database(DATABASE_NAME, TABLE_NAME)
# db.export('C:\Users\madlee\Desktop\RESULT.ppf')

